# cython: language_level=3
# -*- coding: utf-8 -*-

from redis import StrictRedis
import app
import app.utils as utils
import app.utils.util_log as util_log

"""
redis 工具类
"""

class RedisUtils(object):

    def __init__(self):
        self.__redis = StrictRedis(
            host=utils.get_config().get("redis_config", "host"),
            port=utils.get_config().getint("redis_config", "port"),
            db=utils.get_config().getint("redis_config", "db")
            # host=app.config.REDIS_URL,
            # password=app.config.REDIS_PASSWD,
        )

    def getClient(self):
        return self.__redis

    def set(self, key, value,ex=3600):
        result = self.__redis.set(key, value, ex=ex)
        utils.get_logger().debug('redis result %s' % result)

    def get(self, key):
        return self.__redis.get(key)

    def remove(self, key):
        result = self.__redis.delete(key)
        util_log.get_logger().debug("redis result %s" % result)

    def increase(self,key,incr_value):
        return self.__redis.incr(key,incr_value)